package com.hzlx.items.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.items.domain.QualityInspectionItems;
import com.hzlx.items.service.IQualityInspectionItemsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 检验项目明细（定义每个检验标准的具体检查项）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class QualityInspectionItemsController extends BaseController
{
    @Autowired
    private IQualityInspectionItemsService qualityInspectionItemsService;

    /**
     * 查询检验项目明细（定义每个检验标准的具体检查项）列表
     */
    @RequiresPermissions("quality-service:items:list")
    @GetMapping("/items/list")
    public TableDataInfo list(QualityInspectionItems qualityInspectionItems)
    {
        startPage();
        List<QualityInspectionItems> list = qualityInspectionItemsService.selectQualityInspectionItemsList(qualityInspectionItems);
        return getDataTable(list);
    }

    /**
     * 导出检验项目明细（定义每个检验标准的具体检查项）列表
     */
    @RequiresPermissions("quality-service:items:export")
    @Log(title = "检验项目明细（定义每个检验标准的具体检查项）", businessType = BusinessType.EXPORT)
    @PostMapping("/items/export")
    public void export(HttpServletResponse response, QualityInspectionItems qualityInspectionItems)
    {
        List<QualityInspectionItems> list = qualityInspectionItemsService.selectQualityInspectionItemsList(qualityInspectionItems);
        ExcelUtil<QualityInspectionItems> util = new ExcelUtil<QualityInspectionItems>(QualityInspectionItems.class);
        util.exportExcel(response, list, "检验项目明细（定义每个检验标准的具体检查项）数据");
    }

    /**
     * 获取检验项目明细（定义每个检验标准的具体检查项）详细信息
     */
    @RequiresPermissions("quality-service:items:query")
    @GetMapping(value = "/items/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") String itemId)
    {
        return success(qualityInspectionItemsService.selectQualityInspectionItemsByItemId(itemId));
    }

    /**
     * 新增检验项目明细（定义每个检验标准的具体检查项）
     */
    @RequiresPermissions("quality-service:items:add")
    @Log(title = "检验项目明细（定义每个检验标准的具体检查项）", businessType = BusinessType.INSERT)
    @PostMapping("/items")
    public AjaxResult add(@RequestBody QualityInspectionItems qualityInspectionItems)
    {
        return toAjax(qualityInspectionItemsService.insertQualityInspectionItems(qualityInspectionItems));
    }

    /**
     * 修改检验项目明细（定义每个检验标准的具体检查项）
     */
    @RequiresPermissions("quality-service:items:edit")
    @Log(title = "检验项目明细（定义每个检验标准的具体检查项）", businessType = BusinessType.UPDATE)
    @PutMapping("/items")
    public AjaxResult edit(@RequestBody QualityInspectionItems qualityInspectionItems)
    {
        return toAjax(qualityInspectionItemsService.updateQualityInspectionItems(qualityInspectionItems));
    }

    /**
     * 删除检验项目明细（定义每个检验标准的具体检查项）
     */
    @RequiresPermissions("quality-service:items:remove")
    @Log(title = "检验项目明细（定义每个检验标准的具体检查项）", businessType = BusinessType.DELETE)
	@DeleteMapping("/items/{itemIds}")
    public AjaxResult remove(@PathVariable String[] itemIds)
    {
        return toAjax(qualityInspectionItemsService.deleteQualityInspectionItemsByItemIds(itemIds));
    }
}
